package com.observer;

public class StockObserver implements Observer {
	
	private double ibmPrice;
	private double applePrice;
	private double makPrice;
	
	private static int obserrverIDTracker = 0;
	
	private int observerID;
	
	private Subject stockGrabber;
	
	public StockObserver(Subject stockGrabber){		
		this.stockGrabber = stockGrabber;
		this.observerID = ++obserrverIDTracker;
		
		System.out.println("New observer" + this.observerID);
		
		stockGrabber.register(this);
	}

	@Override
	public void update(double ibmPrice, double applePrice, double makPrice) {
		this.ibmPrice = ibmPrice;
		this.applePrice = applePrice;
		this.makPrice = makPrice;
		
		printThePrices();

	}

	public void printThePrices(){
		System.out.println(observerID + "\nIBM: " + ibmPrice +
				"\nAAPL: " + applePrice + "\nMak: " + makPrice + "\n");
	}
}
